<?php
namespace app\api\model;
/**
 * @author: jim
 * @date: 2017/11/8
 */
class CommonModel extends BaseModel
{
    /**
     * 定义一些常量
     * 只属于这个类
     */
    const TYPE_ALL      = 1;
    const TYPE_ID       = 2;
    const TYPE_NAME     = 3;
    const TYPE_AVATAR   = 4;


    // 根据userid返回rongid
    function getRongIdByUserId($userId) {
        $userInfo = $this->db_app->table('customer')
            ->where('Id',$userId)
            ->field("rongCustomerId as rongId")
            ->find();
       return $userInfo['rongId'];
    }

    /**
      *根据rongid获取用户基本信息
      * @param $rongId 用户融云id
      * @param $type 1 全部 2 userId 3 NickName 4 Avatar
      * @return array
      */
    function getUserInfo($rongId,$type = self::TYPE_ALL) {
        $userInfo = $this->db_app->table('customer')
            ->where('rongCustomerId',$rongId)
            ->field("NickName as nickName,Username as userName,TrueName as trueName,Id as userId,avatar,rongCustomerId as rongId")
            ->find();


        // 获取ID
        if ($type == self::TYPE_ID) {
            return $userInfo['userId'];
        }

        // 获取头像
        if ($type == self::TYPE_AVATAR) {
            return $userInfo['avatar'];
        }

        // 获取昵称
        if ($type == self::TYPE_NAME) {
            return $userInfo['nickName'];
        }

        // 获取全部
        if ($type == self::TYPE_ALL) {
            return $userInfo;
        }



    }

}